<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
    require_once("class.connectSQL.inc");
    
    //instancia da classe
    $banco = new connectSQL();
	$banco1 = new connectSQL();
	$banco2 = new connectSQL();
	$banco3 = new connectSQL();
	$banco4 = new connectSQL();
	if(isset($_GET["excluir"])){
				$sql = "Delete from estmarc where codmarc= ".$_GET["cod"]." ";
				//die($sql);
				
				$banco3->Generico($sql);
				//die($_POST["acao"]);
				$msg = "Excluido com sucesso";
			}

	?>

	<head>
	<?php include "head.php"; ?>
 <script>   
    function validar(form){
   
   
    return true;
	}
  </script>
	</head>
	<body>
    	<?php include "sair.php"; ?>
            
            <!-- Header. Main part -->
            <div id="header-main">
                <div class="container_12">
                    <div class="grid_12">
                        <div id="logo">
                            <ul id="nav">
                                <li id="current"><a href="">MARCA</a></li>
                                
                            </ul>
                        </div><!-- End. #Logo -->
                    </div><!-- End. .grid_12-->
                    <div style="clear: both;"></div>
                </div><!-- End. .container_12 -->
            </div> <!-- End #header-main -->
            <div style="clear: both;"></div>
            <!-- Sub navigation -->
          
        </div> <!-- End #header -->
        
		<div class="container_12" align="center" >
        

            <div class="module">
                     <h2><span>Busca de Marca</span></h2>
                        
                     <div class="module-body">
                        <form action="buscamarc.php"  onsubmit="return validar(this);" id="form" method="post">
                        
                          
                            
                            <p align="left">
                                <label>Marca</label>
                                <input type="text" class="input-medium" id="marca" name="marca" value="" />
                                
                            </p>
                            <p align="left">
                                <label>Todos</label>
                                <input type="checkbox"  id="todos" name="todos" value="1" />
                                
                            </p>
                            
                        
                            <fieldset>
                                <input class="submit-green" type="submit" value="Buscar" /> 
                                <input class="submit-gray" type="submit" value="Cancelar" />
                            </fieldset>
                        </form>
                     </div> 
                      <!-- End .module-body -->
					 
                </div>  <!-- End .module -->
			
				
				<?php
				
					if(isset($_POST["marca"])){
						$where = " where desMarca Like '%".$_POST["marca"]."%'";
						if(isset($_POST["todos"])){
								$where = "";
							}
						
					}else{
						$where = " LIMIT 0 , 0";
						}
						
						 if(isset($_GET["where"])){
							   $where = $_GET["where"];
							   }
						
					 $resultado = $banco->Query("SELECT desMarca, codMarc, (
																			SELECT COUNT( B.codMarc ) 
																			FROM estprod AS B
																			WHERE B.CodMarc = A.codMarc
																			) AS prod
																			FROM estmarc AS A".$where);
				?>
                     
        
                <!-- Example table -->
                <div class="module">
                	<h2>Marcas</h2>
                    
                    <div class="module-table-body">
                    	<form action="">
                        <table id="myTable" class="tablesorter">
                        	
                                <tr>
                                    <th style="width:5%">#</th>
                                    <th style="width:20%">Nome</th>
                                    <th style="width:15%"></th>
                                </tr>
                            
                            <tbody>
                            <?php
                            
    
        foreach ($resultado as $resut){
        echo "<tr>";
		echo "<td>". $resut['codMarc']."</td>";
		echo "<td>". $resut['desMarca']."</td>";
		?>
        <td><a href="cadmarc.php?altera=1&cod=<?php echo $resut['codMarc']; ?>"><img src="pencil.gif" tppabs="http://www.xooom.pl/work/magicadmin/images/pencil.gif" width="30" height="30" alt="edit" /></a>
        <?php if($resut['prod'] == 0){?>
        <a href="buscamarc.php?excluir=1&cod=<?php echo $resut['codMarc']; ?>&where=<?php echo $where; ?>"><img src="bin.gif" tppabs="http://www.xooom.pl/work/magicadmin/images/bin.gif" width="30" height="30" alt="delete" /></a>
        <?php  
		}else{
			echo "&nbsp;&nbsp; Essa Marca possui produto vinculado!";
			
			}
			
  		echo "</tr>";
		}
			
   		                  ?>  
                                
                                             
                     
                     
                      </tbody>
                        </table>
                        </form>
                     
                     
                 </div>    
                     
                     
            <div style="clear:both;"></div>
            
            <div style="clear:both;"></div>
        </div> <!-- End .container_12 -->
		
         
        <?php include "footer.php"; ?>
        
	</body>
</html>